<template>
	<view style="padding-bottom: 200rpx;">
		<!-- <view  class="centre-top row" :style="`padding-top:${heightTop}rpx`"
			style="justify-content: space-around;align-items: center;">
			<zywork-icon @click="navTo('/pages/erro/erro')"  type="icon-xiaoxi1" color="#ffffff" size="50"></zywork-icon>
			<view class="row search" style="align-items: center;" @click="navTo('search')">
				<zywork-icon type="icon-sousuo" color="#ffffff" size="50"></zywork-icon>
				<text class="uni-list--sm" style="color: #FFFFFF;margin-left: 30rpx;">请输入搜索内容</text>
			</view>
			<zywork-icon @click="open" type="icon-kefu" color="#ffffff" size="50"></zywork-icon>
		</view> -->
		<view class="centre-top1 row" style="justify-content: space-around;position: relative;z-index: 1;"
			:style="`padding-top:${height}rpx`">
			<view @click="checkSystemLocationStatus()" class="column align-items-center"
				style="width: 200rpx;height: 200rpx;margin-top: 20rpx;">
				<zywork-icon type="icon-saoyisao" color="#fff" size="100"></zywork-icon>
				<text style="color: #FFFFFF;font-size: 38rpx;margin-top: 10rpx;">扫一扫</text>
			</view>

			<view class="column align-items-center" style="width: 200rpx;height: 200rpx;margin-top: 20rpx;"
				@click="navTo('/pages/user/my-QR-code/my-QR-code')">
				<zywork-icon type="icon-erweima" color="#fff" size="100" style="transform:scale(0.9);"></zywork-icon>
				<text style="color: #FFFFFF;font-size: 38rpx;margin-top: 10rpx;">我的推荐码</text>
			</view>
		</view>
		<view class="centre-grid">
			<view class="row">
				<view class="column" style="position: relative;" @click="navTo('/pages/index/make-money/make-money')">
					<image :class="'animation-' + animation" src="/static/index/icon_home_money.png" mode=""></image>
					<image v-if="isGif" :src="gifUrl" style="width: 400rpx;position: absolute;top: -40rpx;"
						mode="widthFix">
					</image>
					<text class="text-18">我要赚钱</text>
				</view>
				<view v-if="iosStatus" class="column" @click="navTakeOutOffer">
					<image src="/static/index/menu/home-btn-coupons@3x.png" mode=""></image>
					<text class="text-18">外卖优惠</text>
				</view>
				<view v-if="iosStatus" class="column" @click="reLaunch('/pages/tao-bao/tao-bao','TB')">
					<image src="/static/index/menu/home-btn-Shopping.png" mode=""></image>
					<text class="text-18">购物福利</text>
				</view>
				<view v-if="iosStatus" class="column" @click="navOldClothesRecycling">
					<image src="/static/index/menu/home-btn-recycling@3x.png" mode=""></image>
					<text class="text-18">旧衣回收</text>
				</view>
				<view v-if="iosStatus" class="column" @click="navTo('/pages/index/nearby-facility/nearby-facility')">
					<image src="/static/index/menu/home-btn-equipment@3x.png" mode=""></image>
					<text class="text-18">附近设备</text>
				</view>
			</view>

			<view class="row" v-if="false">
				<view class="column" style="position: relative;" @click="navTo('/pages/index/make-money/make-money')">
					<image :class="'animation-' + animation" src="/static/index/icon_home_money.png" mode=""></image>
					<image v-if="isGif" :src="gifUrl" style="width: 400rpx;position: absolute;top: -40rpx;"
						mode="widthFix">
					</image>
					<text class="text-18">我要赚钱</text>
				</view>
				<view v-if="iosStatus" class="column" @click="reLaunch('/pages/tao-bao/tao-bao','TB')">
					<image src="/static/icon_home_taobao@2x.png" mode=""></image>
					<text class="text-18">购物福利</text>
				</view>
				<view v-if="iosStatus&&!isAndroid" class="column" @click="reLaunch('/pages/tao-bao/tao-bao','PDD')">
					<image src="/static/icon_home_spell@2x.png" mode=""></image>
					<text class="text-18">拼多多</text>
				</view>
				<view v-if="iosStatus&&isAndroid" class="column" @click="navTo('/pages/index/video-ks/video-ks')">
					<image src="/static/index/kuaiShou.png" mode=""></image>
					<text class="text-18">热门视频</text>
				</view>
				<view v-if="!iosStatus" class="column" @click="navTo('/pages/user/order/order_list')">
					<image src="/static/icon_my_order@3x.png" mode=""></image>
					<text class="text-18">我的订单</text>
				</view>
				<view v-if="!iosStatus" class="column" @click="navTo('/pages/user/feedback/feedback')">
					<image src="/static/icon_my_feedback@3x.png" mode=""></image>
					<text class="text-18">反馈中心</text>
				</view>
				<view class="column" @click="navTo('/pages/index/nearby-facility/nearby-facility')">
					<image src="/static/icon_home_equipment@2x.png" mode=""></image>
					<text class="text-18">附近设备</text>
				</view>
			</view>
			<noticeBar :speed="speed" textColor="#ff5500"
				style="width: 90%;position: absolute;bottom: -40rpx;z-index: 1;" :list="noticeList"></noticeBar>
		</view>
		<!-- <information-ad /> -->
		<view v-if="iosStatus && false" style="width: 90%;left: 5000rpx;margin: 0 auto;" :style="`position:${initial}`">
			<ad type="feeds" guang :data="adData" @close="adClose">
			</ad>
		</view>

		<view @click="navOldClothesRecycling" class="row align-items-center" style="margin-top: 20rpx;">
			<image src="/static/241638775265_.pic_hd.jpg" style="width: 720rpx;" mode="widthFix"></image>
		</view>

		<view @click="navTo('/pages/index/daily-Quest/daily-Quest')" class="row align-items-center"
			style="margin-top: 20rpx;">
			<image src="/static/image_capsule@3x.png" style="width: 720rpx;" mode="widthFix"></image>
		</view>
		<view class="row align-items-center" v-if="false">
			<!-- <image src="/static/image_capsule@3x.png" style="width: 720rpx;" mode="widthFix"></image> -->
			<image class="advertising-img" src="/static/ceshi/hangz.jpg" mode="scaleToFill">
			</image>
		</view>
		<view style="padding: ;padding: 20rpx 20rpx;">
			<view class="">
				<!-- <view class="row advertising " @click="showAd" style=""> -->
				<view v-for="(item,index) in thirdConfigList" v-show="item.isShow&&!item.dataValid&&iosStatus"
					class="row advertising " style="">
					<image v-if="item.imgUrl" :src="item.imgUrl" mode="widthFix"></image>
					<view class="column " style="">
						<text class="text-lg" style="">{{item.title}}</text>
						<text class="text-sm">{{item.subtitle}}</text>
					</view>
					<view class="button" style="" @click="redPacket(item)">
						{{item.buttonTitle}}
					</view>
				</view>
				<!-- <view class="row advertising " style="">
					<image src="/static/index/Ele.png" mode="widthFix"></image>
					<view class="column ">
						<text class="text-lg">免费领饿了么红包</text>
						<text class="text-sm" style="">立马到账，优惠不停</text>
					</view>
					<view class="button" @click="redPacket(0)" style="">
						立即领取
					</view>
				</view>
				
				<view class="row advertising " style="">
					<image src="/static/index/meituan.png" mode="widthFix"></image>
					<view class="column ">
						<text class="text-lg">美团外卖红包</text>
						<text class="text-sm">免费领取，秒到账</text>
					</view>
					<view class="button" @click="redPacket(1)" style="">
						立即领取
					</view>
				</view>
				
				<view class="row advertising " style="">
					<image src="/static/index/KFC.png" mode="widthFix"></image>
					<view class="column ">
						<text class="text-lg">KFC在线点餐</text>
						<text class="text-sm">5折起</text>
					</view>
					<view class="button" @click="redPacket(2)" style="">
						立即点餐
					</view>
				</view>
				
				<view class="row advertising " style="">
					<image src="/static/index/Movie-Tickets.png" mode="widthFix"></image>
					<view class="column ">
						<text class="text-lg">看电影</text>
						<text class="text-sm">85折起</text>
					</view>
					<view class="button" @click="redPacket(3)" style="">
						立即购买
					</view>
				</view>
				
				<view class="row advertising " style="">
					<image src="/static/index/prepaid.png" mode="widthFix"></image>
					<view class="column ">
						<text class="text-lg">充话费</text>
						<text class="text-sm">95折起</text>
					</view>
					<view class="button" @click="redPacket(4)" style="">
						立即充值
					</view>
				</view>
				<view class="row advertising " style="">
					<image src="/static/index/didi.png" mode="widthFix"></image>
					<view class="column ">
						<text class="text-lg">滴滴专享出行</text>
						<text class="text-sm">最高8折起</text>
					</view>
					<view class="button" @click="redPacket(5)" style="">
						立即领券
					</view>
				</view> -->
			</view>

			<view class="" style="font-size: 40rpx;padding: 30rpx 0rpx;">
				动态资讯
			</view>
			<view class="article-list" style="padding: 30rpx 0rpx;">
				<view v-for="(item,index) in articleList" :key="index" @click="itemClick(index,item)" class="row"
					style="align-items: center;margin-bottom: 30rpx;">
					<image v-if="item.raw.imgurl" :src="item.raw.imgurl" mode="scaleToFill"></image>
					<view class="column column-article" style="">
						<view class="label" :contents="item.source">
							{{item.title}}
						</view>
						<view class="row label-text">
							<text
								style="color: #4589A6;overflow: hidden;text-overflow: ellipsis;width: 120rpx;height: 30rpx;white-space:nowrap;">{{item.type}}</text>
							<text style="margin-left: 20rpx;">{{item.readingQuantity}}阅读</text>
							<text style="margin-left: auto;">{{item.time}}</text>
						</view>
					</view>
				</view>
			</view>
			<view v-show="isLoadMore">
				<uni-load-more :status="loadStatus"></uni-load-more>
			</view>
			<!-- <z-paging :fixed="false" :refresherEnabled="false" style="height: 800rpx;" ref="paging"
				v-model="articleList" @query="queryList" :loadingMoreCustomStyle="{paddingBottom:'220rpx'}">
				
			</z-paging> -->
		</view>
		<custom-tab-bar :isAndroid="iosStatus" :current="1" @click="switchTabs"></custom-tab-bar>
		<uni-popup @change="popupWithdrawalShow" ref="alertDialog" type="dialog" :maskClick="false">
			<uni-popup-dialog type="warning" title="客服电话" :buttonArr="['取消','拨打']" :content="phoneNumber"
				@confirm="dialogConfirm" @close="dialogClose"></uni-popup-dialog>
		</uni-popup>
		<uni-popup @change="popupWithdrawalShow" ref="hintDialog" type="dialog" :maskClick="false">
			<uni-popup-dialog type="warning" :buttonArr="['取消','跳转设置']" content="您还未给定位权限,请到设置中允许使用您的位置信息"
				@confirm="dialogConfirm1" @close="dialogClose1"></uni-popup-dialog>
		</uni-popup>
		<uni-popup @change="popupWithdrawalShow" ref="signInDialog" type="dialog" :maskClick="false">
			<view class="popup-content">
				<view class="" style="text-align: center;font-size: 35rpx;color: #dd1e14;font-weight: 800;">
					新用户免费领取5个环保袋
				</view>

				<view class="row" style="align-items: center;margin-top: 20rpx;flex-wrap: wrap;">
					<view v-for="(item,index) in meetTheGetconditionLst" class="popup-content-item"
						:style="`border: solid 5rpx ${item.color};`">
						<view v-if="item.createTime === currentTime&&item.type===0" class="" style="">
							可领取
						</view>
						<view v-else-if="item.type===1" class="" style="background-color: #ffaa00;">
							已领取
						</view>
						<view v-else-if="item.createTime < currentTime&&item.type===2" class=""
							style="background-color: #ababab;">
							已过期
						</view>
						<view v-else-if="item.createTime > currentTime&&item.type===0" class=""
							style="background-color: #57BE6A;">
							第{{week[index]}}天
						</view>
						<view class="" :style="`color: ${item.color};`">
							{{signInItemValue}}云豆
						</view>
					</view>
					<!-- <view class="popup-content-item" style="border: solid 5rpx #57BE6A;">
						<view class="" style="background-color: #57BE6A;">
							第二天
						</view>
						<view class="" style="color: #57BE6A;">
							500云豆
						</view>
					</view>
					<view class="popup-content-item" style="border: solid 5rpx #57BE6A;">
						<view class="" style="background-color: #57BE6A;">
							第三天
						</view>
						<view class="" style="color: #57BE6A;">
							500云豆
						</view>
					</view>
					<view class="popup-content-item" style="border: solid 5rpx #57BE6A;">
						<view class="" style="background-color: #57BE6A;">
							第四天
						</view>
						<view class="" style="color: #57BE6A;">
							500云豆
						</view>
					</view>
					<view class="popup-content-item" style="border: solid 5rpx #57BE6A;">
						<view class="" style="background-color: #57BE6A;">
							第五天
						</view>
						<view class="" style="color: #57BE6A;">
							500云豆
						</view>
					</view> -->
				</view>
				<view class="popup-button" @click="showRewardedVideoAd">
					立即领取云豆
				</view>
				<view class="popup-bottom">
					看完视频后即可得{{signInItemValue}}云豆
				</view>
			</view>
		</uni-popup>


	</view>
</template>

<script>
	import {
		mapMutations,
		mapState
	} from 'vuex';
	import gcoord from 'gcoord';
	import informationAd from '@/components/ad/information-ad.vue'
	import APPUpdate, {
		getCurrentNo
	} from '@/uni_modules/zhouWei-APPUpdate/js_sdk/appUpdate';
	import noticeBar from '@/components/notice-bar/notice-bar.vue'
	import {
		urlList
	} from '@/common/picker-data.js'
	import AD from "@/common/advertising.js"
	import permision from "@/js_sdk/wa-permission/permission.js" //引入权限判断，主要解决部分机型扫码出现问题
	import {
		launchMiniProgram
	} from '../../utils/share.js';

	export default {
		components: {
			informationAd,
			noticeBar
		},
		data() {
			return {
				noticeList: [], //中奖信息列表
				speed: 80, //中奖信息滚动速度
				articleContentItem: "企业文化",
				animation: 'shake', // 动画样式
				isGif: false,
				gifUrl: "/static/index/money.gif",
				heightTop: 25,
				height: 30,
				phoneNumber: "",
				articleList: [],
				articleIndex: 0,
				equipment: "",
				consultPage: 1,
				isShow: true,
				adData: {},
				initial: "initial",
				loadStatus: 'loading', //加载样式：more-加载前样式，loading-加载中样式，nomore-没有数据样式
				isLoadMore: false, //是否加载中
				loading: false,
				watchTheTime: 0, //快手视频计时
				timeVideo: null,
				requestCount: 0, //广告请求计数
				labelCount: 1, //判断标签是否设置过
				backButtonPress: 0, //监听退出应用的事件
				isAndroid: true, //判断是否是安卓环境
				adOptions: {
					adpid: 1027948601
				},
				thirdConfigList: [], //配置信息
				systemInfo: "",
				hasUserInfo: false,
				meetTheGetconditionLst: [],
				iosStatus: 0, //ios审核时后台字典设置成0不显示
				week: ['一', '二', '三', '四', '五'],
				signInItemValue: 80
			}
		},
		created() {
			uni.hideTabBar({})
			this.phoneNumber = this.$util.PHONE_NUMBER;
			this.articleList = uni.getStorageSync("articleList") || []
			this.queryList() //资讯动态
			this.userInfo = uni.getStorageSync(this.$util.USER_INFO) || {}
			this.thirdConfigList = uni.getStorageSync('thirdConfigList') || []
			this.isAndroid = getApp().globalData.isAndroid;
			let i = 0
			this.noticeList = []
			while (i < 50) {
				this.getName();
				i++;
			}
			if (this.$environment === 'prod') {
				this.appUpdate(); //查询是否有新版本需要更新
			}

		},
		computed: {
			...mapState(['codeResults']),
		},
		watch: {
			codeResults(res) {
				if (getApp().globalData.index == 1) {
					this.scanResult(res.result);
				}
			}
		},
		onPullDownRefresh() {
			this.articleList = []
			this.queryList()
			setTimeout(function() {
				uni.stopPullDownRefresh();
			}, 1000);
		},
		onReady() {
			setTimeout(() => {
				if (this.iosStatus && this.hasUserInfo) {
					let adpid = 1334171383
					if (!this.isAndroid && this.iosStatus) {
						adpid = 1912851438
					}
					var interstitialAd = uni.createInterstitialAd({
						adpid: adpid
					})
					interstitialAd.show().catch((err) => {
						console.error(err)
					})
					interstitialAd.onClose(res => {
						this.getMeetTheGetcondition();
					})
					this.getAdData(); //加载广告
				}
			}, 5000)
		},
		onLoad() {
			this.interval();
			this.systemInfo = uni.getSystemInfoSync();
			//动画效果初始化
			this.timerShake = setInterval(() => {
				this.animation = 'shake';
				this.interval();
			}, 4000)
			// 获取设备信息
			let that = this;
			setTimeout(() => {
				if (this.hasUserInfo) {
					if (!this.systemInfo.deviceId) {
						this.systemInfo.deviceId = this.$util.getClientId();
						console.log("系统信息设备编码1", this.systemInfo.deviceId)
					}
					if (this.systemInfo.deviceId.indexOf("000000") != -1) {
						this.systemInfo.deviceId = this.$util.getClientId();
						console.log("系统信息设备编码2", this.systemInfo.deviceId)
					}
					this.getUserDevice()
					this.getProvinces(); //加载省市区
				}
			}, 1000)
		},
		onShow() {
			this.iosStatus = uni.getStorageSync("iosStatus")
			this.currentTime = this.$util.getTime().split(" ")[0]
			// if (this.initial == "absolute") {
			// 	this.initial = "initial"
			// 	this.$refs.alertDialog.close()
			// }
			if (this.timeVideo) {
				clearInterval(this.timeVideo);
				this.timeVideo = null;
			}
			getApp().globalData.index = 1
			this.hasUserInfo = uni.getStorageSync(this.$util.HAS_USER_INFO)
			// uni.setStorageSync(this.$util.AUTH,false)
			// uni.removeStorageSync(this.$util.USER_TOKEN_KEY)
			// uni.setStorageSync(this.$util.HAS_USER_INFO,false)
			// #ifdef APP-PLUS

			if (this.hasUserInfo) {
				setTimeout(() => {
					this.getUserInfo();
					this.getThirdConfig();
					this.queryLable(); //加载爱好标签
					this.getZhuce();
				}, 1000)
			} else {
				this.labelCount = 1;
				this.userInfo = {
					phonenumber: "0000"
				}
			}
			// #endif
			let that = this;
			uni.onNetworkStatusChange(function(res) {
				console.log("网络信息", res.isConnected);
				if (!res.isConnected) {
					that.$util.showInfoToast("网络连接已断开");
				}
				console.log(res.networkType);
			});
			this.getAPP();
		},
		onReachBottom() { //上拉触底函数
			if (!this.isLoadMore) { //此处判断，上锁，防止重复请求
				this.isLoadMore = true
				this.consultPage += 1
				this.queryList()
			}
		},
		onNavigationBarSearchInputClicked() {
			this.navTo('search')
		},
		onNavigationBarButtonTap({
			index
		}) {
			if (index === 0) {
				this.navTo('/pages/index/message/message');
			} else {
				this.open();
			}
		},
		onBackPress() {
			this.backButtonPress++;
			if (this.backButtonPress > 1) {
				this.logout();
				plus.runtime.quit();
			} else {
				plus.nativeUI.toast('再按一次退出应用');
			}
			setTimeout(function() {
				this.backButtonPress = 0;
			}, 1000);
			return true;
		},
		methods: {
			//告诉APP.vue 生命周期停止统计在线时长
			...mapMutations(['logout']),
			...mapMutations(['setWatchTime']),
			// 跳转旧衣回收小程序
			navOldClothesRecycling() {
				launchMiniProgram({
					appId: 'gh_2c6084f1711a',
					path: 'wjyk_recycle/pages/index/index'
				});
			},
			navTakeOutOffer() {
				launchMiniProgram({
					appId: 'gh_46a278d3fd13',
					path: 'pages/main/home/index'
				});
			},
			getZhuce() {
				this.$util.doGet("/dict/getDictItemByName?dictCode=integralRule&itemName=zhuce", {}, {}, false)
					.then(res => {
							if (res.data.code == this.$ResponseStatus.OK) {
								this.signInItemValue = res.data.data.itemValue;
							}
						}).catch(error => {
						console.log(error)
					})
			},
			color(item) {
				if (item.createTime > this.currentTime && item.type === 0) {
					return '#57BE6A'
				} else if (item.createTime < this.currentTime && item.type === 2) {
					return '#ababab'
				} else if (item.type === 1) {
					return '#ffaa00'
				} else {
					return '#EB5936'
				}
			},
			getMeetTheGetcondition() {
				this.$util.doGet("/SendPointsEveryDay/meetTheGetcondition", {}, {}, true).then(res => {
					// console.log("查询标签是否设置", res)
					if (res.data.code == this.$ResponseStatus.OK) {
						console.log("获取签到信息列表", res.data)
						this.isMeetTheGetcondition = res.data.data.status
						if (this.isMeetTheGetcondition) {
							console.log("当前时间", this.currentTime)
							this.meetTheGetconditionLst = res.data.data.result
							this.meetTheGetconditionLst.forEach(item => {
								item.color = this.color(item);
								if (item.createTime === this.currentTime && item.type === 0) {
									this.$refs.signInDialog.open()
								}
							})
						}
					}
				}).catch(error => {
					console.log(error)
				})
			},
			showRewardedVideoAd() {
				if (this.userInfo.loginType && this.userInfo.loginType === 'apple' && !this.userInfo.phonenumber) {
					this.navTo('/pages/login/binding-phone/binding-phone?type=' + this.userInfo.loginType);
					return
				}
				if (this.userInfo.loginType && this.userInfo.loginType === 'wx' && !this.userInfo.phonenumber) {
					this.navTo('/pages/user/my-setting/update-Phone/update-Phone');
					return
				}
				let adpid = uni.getStorageSync(this.$util.ADPID);
				// this.adpid = 1360037533
				// this._isLoaded = false
				// console.log("广告位",this.adpid)
				console.log(this.isAndroid)
				if (!this.isAndroid) {
					adpid = 1281678491
				}
				if (this.$environment === 'dev' && this.isAndroid) {
					adpid = 1471114933
				}
				this.$forceUpdate()
				let options = {
					adpid: adpid, // HBuilder 基座测试广告位
					adType: "RewardedVideo",
					urlCallback: {
						// userId: this.userInfo.rcode,
						userId: '',
						extra: "testdata",
					}
				}
				let ad = AD.get(options)
				AD.show(options, (res) => {
					// 用户点击了【关闭广告】按钮
					console.log("领取激励奖励", res)

					if (res && res.isEnded) {
						this.receiveAward();
					} else {
						// 播放中途退出
						console.log("onClose " + res.isEnded);
					}
				}, (err) => {
					// 广告加载错误
					console.log(err)
				})
			},
			receiveAward() {
				this.$util.doPostJson("/SendPointsEveryDay/saveMeetTheGetcondition", {}, {}, true).then(res => {
					console.log("领取成功", res)
					this.$refs.signInDialog.close()
					if (res.data.code == this.$ResponseStatus.OK) {
						this.$util.showInfoToast("领取成功")
					} else {
						this.$util.showInfoToast("领取奖励失败")
					}
				});
			},
			deviceIdReplace() {
				if (this.systemInfo.deviceId.indexOf("|") != -1) {
					this.systemInfo.deviceId = this.systemInfo.deviceId.replace("|", "");
					this.deviceIdReplace();
				}
			},
			getUserDevice() {
				uni.setStorageSync(this.$util.UUID, this.systemInfo.deviceId);
				this.deviceIdReplace();
				let data = {
					deviceId: this.systemInfo.deviceId, //系统唯一编码
					language: this.systemInfo.language || '', //系统语言
					systemEdition: this.systemInfo.system || '', //系统版本
					manufacturer: this.systemInfo.brand || '', //设备型号
					systemName: this.systemInfo.platform || '', //系统名称
					supplier: this.systemInfo.brand || '', //系统供应商
					model: this.systemInfo.model || '', //设备型号
				}
				this.$util.doPostJson("/userDevice/add", data, {}, true).then(res => {
					if (res.data.code == this.$ResponseStatus.OK) {
						// 兼容之前的版本（updateType是新版才有的参数）
						console.log("提交成功,系统信息", data)
					}
				});
			},
			onadload(e) {
				console.log("onload");
			},
			onaderror(e) {
				console.log("onerror");
			},
			//缓存APP版本信息
			getAPP() {
				let platform = uni.getSystemInfoSync().platform;
				let httpData = {
					vn: 0
				}
				if (platform == "android") {
					httpData.type = 1;
				} else {
					httpData.type = 2;
				}
				this.$util.doPostForm("/version/versionNumber", httpData, {}, false).then(res => {
					/* res的数据说明
					 * | 参数名称        | 一定返回     | 类型        | 描述
					 * | -------------|--------- | --------- | ------------- |
					 * | versionCode     | y        | int       | 版本号        |
					 * | versionName     | y        | String    | 版本名称      |
					 * | downloadUrl     | y        | String    | 版本下载链接（IOS安装包更新请放跳转store应用商店链接,安卓apk和wgt文件放文件下载链接）  |
					 */
					if (res.data.code == this.$ResponseStatus.OK) {
						// 兼容之前的版本（updateType是新版才有的参数）
						uni.setStorageSync(this.$util.APP_VERSION, res.data.data)
					} else {}
				});
			},
			async getUserTime() {
				const {
					data
				} = await this.$util.doGet(`/report/selectOnlinetime`, {}, {}, true)
				if (data.code == this.$ResponseStatus.OK) {
					this.time = data.data
					this.setWatchTime(this.time)
				} else { //接口请求失败的处理
					this.setWatchTime(0)
				}
			},
			async getThirdConfig() {
				const {
					data
				} = await this.$util.doGet(`/thirdConfig/list`, {}, {}, true)
				if (data.code == this.$ResponseStatus.OK) {
					this.thirdConfigList = data.data.list
					this.thirdConfigList.forEach(item => {
						if (item.showStatus === 2) {
							item.isShow = true
						} else if (this.isAndroid && item.showStatus === 1) {
							item.isShow = true
						} else if (!this.isAndroid && item.showStatus === 0) {
							item.isShow = true
						}
						if (item.title.indexOf('公众号') != -1) {
							uni.setStorageSync("qcPlay", item)
						}
					})
					uni.setStorageSync('thirdConfigList', this.thirdConfigList)
					this.$forceUpdate();
					// console.log("配置信息", this.thirdConfigList)
				} else { //接口请求失败的处理
					this.thirdConfigList = uni.getStorageSync('thirdConfigList') || []
				}
			},
			getMovieTicketsAuthorization() {
				if (this.authStatus) {
					return
				}
				this.authStatus = true
				this.$util.doGet("/live/getLiveUrl", {}, {}, true).then(res => {
					if (res.data.code == this.$ResponseStatus.OK) {
						if (res.data.data) {
							this.navTo("/pages/common/common?weburl=" + res.data.data)
						}
					}
					setTimeout(() => {
						this.authStatus = false
					}, 1000)
				}).catch(error => {
					console.log(error)
				})
			},
			getKfcAuthorization() {
				if (this.authStatus) {
					return
				}
				this.authStatus = true
				this.$util.doGet("/kfc/getKfcUrl", {}, {}, true).then(res => {
					if (res.data.code == this.$ResponseStatus.OK) {
						if (res.data.data) {
							console.log("KFC", res.data.data)
							this.navTo("/pages/common/common?weburl=" + res.data.data)
						}
					}
					setTimeout(() => {
						this.authStatus = false
					}, 1000)
				}).catch(error => {
					console.log(error)
				})
			},
			redPacket(item) {
				this.$util.accessPage(item.id)
				if (item.type === 0) {
					this.navTo(item.url)
				} else if (item.type === 1) {
					plus.runtime.openURL(item.url);
				} else if (item.type === 2) {
					if (item.title.indexOf("KFC") != -1) {
						this.getKfcAuthorization();
					} else if (item.title.indexOf("电影") != -1) {
						this.getMovieTicketsAuthorization();
					}
				} else if (item.type === 3) {
					this.navTo(`/pages/common/common?weburl=${item.url}`)
				}
			},
			//走马灯数据
			getName() {
				let family_name_str =
					"赵钱孙李周吴郑王冯陈褚卫蒋沈韩杨朱秦尤许吕施张孔曹严华金魏陶姜戚谢邹喻柏水窦章云苏潘葛奚范彭郎鲁韦昌马苗凤花方俞任袁柳酆鲍史唐费廉岑薛雷贺倪汤滕殷罗毕郝邬安常乐于时傅皮卞齐康伍余元卜顾孟平黄和穆萧尹";
				let family_name_index = Math.floor(Math.random() * family_name_str.length) + 1
				let family_name = family_name_str.substring(family_name_index, family_name_index + 1);
				let name = family_name + "***累计提现了" + (Math.floor(Math.random() * 10) + 1) * 10 + "元";
				this.noticeList.push(name)
			},
			//快手内容联盟
			showAd() {
				if (this.labelCount === 0) {
					this.navTo("/pages/index/interest/interest")
					return;
				}
				if (!this.userInfo.phonenumber && this.isAndroid) {
					this.navTo("/pages/user/my-setting/update-Phone/update-Phone")
					return;
				}
				if (this.loading) {
					return;
				}
				// uni.setStorageSync(this.dayTime,3600)
				this.loading = true;
				plus.ad.showContentPage(this.adOptions, (res) => {
					this.loading = false;
					this.timeVideo = setInterval(() => {
						this.watchTheTime++
						if (this.watchTheTime != 0 && this.watchTheTime % 60 == 0) {
							console.log(this.watchTheTime)
							uni.setStorageSync(this.dayTime, this.watchTheTime)
						}
					}, 1000)
				}, (err) => {
					this.loading = false;
					console.log(err);
				});
			},
			//APP更新请求
			appUpdate() {
				getCurrentNo(res => {
					// 进页面获取当前APP版本号（用于页面显示）
					this.version = res.version;
				});
				APPUpdate(false);
			},
			adClose() {
				this.initial = "absolute"
			},
			//加载信息流广告
			getAdData() {
				// 仅APP平台支持
				// 1862455929

				let screenHeight = uni.getSystemInfoSync().screenHeight
				let adpid = 1862455929
				if (screenHeight > 780) { //屏幕高度大于780的才展示视频广告
					adpid = 1798984976;
				}
				console.log("所在系统环境", this.isAndroid)
				console.log("所在系统环境值", this.iosStatus)
				if (!this.isAndroid && this.iosStatus) {
					adpid = 1433206601
					if (screenHeight > 780) { //屏幕高度大于780的才展示视频广告
						if (!this.isAndroid && this.iosStatus) {
							adpid = 1131480982
						}
					}
				}

				plus.ad.getAds({
						adpid: adpid, // 替换为自己申请获取的广告位标识，此广告位标识仅在HBuilderX标准基座中有效，仅用于测试
						count: 3, // 广告数量，默认 3
					},
					(res) => {
						// 注意: 广告数据只能使用一次
						this.adData = res.ads[0];
						this.requestCount = 0
					},
					(err) => {
						console.log(err);
						if (err.code === -5005 && this.requestCount !== 3) {
							this.requestCount++
							this.getAdData();
						}
						if (err.code === -5002 && this.requestCount <= 3) {
							this.requestCount++
							this.getAdData();
						}
					}
				)

			},
			//拨打客服电话把信息流广告隐藏起来
			open() {
				// this.isShow = false
				// this.initial = "absolute"
				this.$refs.alertDialog.open()
			},
			closeDialog() {
				this.$refs.alertDialog.close()
				// this.initial = "initial"
			},
			//查询用户是否设置过标签
			queryLable() {
				this.$util.doGet("/label/userOneLabelList", {}, {}, true).then(res => {
					// console.log("查询标签是否设置", res)
					if (res.data.code == this.$ResponseStatus.OK) {
						this.labelCount = res.data.rows.length;
					}
				}).catch(error => {
					this.labelCount = 1
					console.log(error)
				})
			},
			async getMicInforList(page = this.consultPage) {
				try {
					const {
						data: {
							code,
							message,
							data: {
								list,
								pageNum,
								pageSize
							},
						}
					} = await this.$util.getMicInforList(page)
					if (code == this.$ResponseStatus.OK) {
						if (list) {
							if (list.length < pageSize) {
								this.isLoadMore = true
								this.loadStatus = 'nomore'
							} else {
								this.isLoadMore = false
							}
							if (pageNum == page) {
								return list.map(it => {
									return {
										title: it.articleTitle,
										source: it.subtopics,
										type: it.publisher,
										readingQuantity: it.pageView,
										time: it.releaseTime,
										raw: it
									}
								})
							} else {
								this.isLoadMore = true
								this.loadStatus = 'nomore'
								return []
							}

						} else {
							this.isLoadMore = true
							this.loadStatus = 'nomore'
							return []
						}
					} else { //接口请求失败的处理
						uni.showToast({
							title: message,
							icon: 'none'
						})
						this.isLoadMore = false
						if (this.consultPage > 1) {
							this.consultPage -= 1
						}
						return []
					}

				} catch (e) {
					console.warn(e)
					return []
				}
			},
			getUserInfo() {
				this.$util.doGet('/user/manager/userInfoList', {}, {}, true).then(res => {
					if (res.data.code == this.$ResponseStatus.OK) {
						uni.setStorageSync(this.$util.USER_INFO, res.data.data)
						this.userInfo = res.data.data
						this.dayTime = "user_" + this.userInfo.rcode + '_1' + this.$util
							.getTime().split(" ")[0]
						if (uni.getStorageSync(this.dayTime)) {
							this.watchTheTime = uni.getStorageSync(this.dayTime)
						}
						this.getUserTime();
						console.log("用户个人信息", this.userInfo)
						this.$forceUpdate();
					}
				}).catch(error => {
					console.log(error)
					this.userInfo = uni.getStorageSync(this.$util.USER_INFO) || {}
				})
			},
			//加载省市区三级联动数据
			getProvinces() {
				this.$util.doGet('/region/getRegionList', {}, {}, true).then(res => {
					if (res.data.code == this.$ResponseStatus.OK) {
						uni.setStorageSync(this.$util.PROVINCE, res.data.data)
					}
				}).catch(error => {
					console.log(error)
				})
			},
			dialogConfirm1() {
				permision.gotoAppPermissionSetting();
			},
			dialogClose1() {
				// this.initial = "initial"
			},
			popupWithdrawalShow({
				show
			}) {
				if (show) {
					this.initial = "absolute"
				} else {
					this.initial = "initial"
				}
			},
			async checkSystemLocationStatus() {
				if (permision.checkSystemEnableLocation()) {
					if (uni.getSystemInfoSync().platform == 'ios') {
						let result = await permision.judgeIosPermission("location")
						if (result) {
							this.scan()
						} else {
							this.$refs.hintDialog.open()
						}
					}
					if (uni.getSystemInfoSync().platform == 'android') {
						permision.requestAndroidPermission(
							'android.permission.ACCESS_FINE_LOCATION').then(res => {
							console.log("位置权限状态", res)
							if (res === 1) {
								this.scan()
							} else {
								this.$refs.hintDialog.open()
							}
						}).catch(error => {
							console.log(error)
						})
					}
				} else {
					this.getLocationJurisdiction()
				}
				// var result = permision.checkSystemEnableLocation()
				// console.log(result);
			},
			getLocationJurisdiction() {
				if (uni.getSystemInfoSync().platform == 'android') {
					var Intent = plus.android.importClass('android.content.Intent');
					var Settings = plus.android.importClass('android.provider.Settings');
					var intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
					var main = plus.android.runtimeMainActivity();
					main.startActivity(intent); // 打开系统设置GPS服务页面
				}
				// ios平台
				if (uni.getSystemInfoSync().platform == 'ios') {
					var UIApplication = plus.ios.import("UIApplication");
					var application2 = UIApplication.sharedApplication();
					var NSURL2 = plus.ios.import("NSURL");
					var setting2 = NSURL2.URLWithString("App-Prefs:root=Privacy&path=LOCATION");
					application2.openURL(setting2);
					plus.ios.deleteObject(setting2);
					plus.ios.deleteObject(NSURL2);
					plus.ios.deleteObject(application2);
				}
			},
			scanCode() {
				uni.scanCode({
					success: res => {
						uni.showLoading({
							title: "开始识别"
						})
						this.scanResult(res.result);
					}
				})
			},
			scan() {
				if (uni.getSystemInfoSync().platform == 'ios') {
					this.scanCode();
				} else {
					permision.requestAndroidPermission('android.permission.CAMERA').then(res => {
						console.log("权限状态", res)
						if (res === 1) {
							this.scanCode();
						}
					}).catch(error => {
						console.log(error)
					})
				}
			},
			// 判断设备是否在附近
			distance() {
				var La1 = (this.equipLatitude * Math.PI) / 180.0
				var La2 = (this.latitude * Math.PI) / 180.0
				var La3 = La1 - La2
				var Lb3 = (this.equipLongitude * Math.PI) / 180.0 - (this.longitude * Math.PI) /
					180.0
				var s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(La3 / 2), 2) + Math.cos(La1) *
					Math.cos(La2) * Math.pow(
						Math.sin(Lb3 / 2), 2)))
				s = s * 6378.137 // 地球半径
				s = Math.round(s * 10000) / 10000 - 0.5 // 减去0.1km
				let distanceKm = s
				s = s * 1000
				return s - 15
			},
			iosDistance() {
				let PI = 3.14159265358979323; //圆周率
				let R = 6371229; //地球半径

				var lng1 = this.longitude;
				var lat1 = this.latitude;

				var lng2 = this.equipLongitude;
				var lat2 = this.equipLatitude;

				let x, y, distance;
				let lonres = lng1 > lng2 ? lng1 - lng2 : lng2 - lng1;
				let latres = lat1 > lat2 ? lat1 - lat2 : lat2 - lat1;
				x = (lonres) * PI * R * Math.cos(((lat1 + lat2) / 2) * PI / 180) / 180;
				y = (lat2 - lat1) * PI * R / 180;
				distance = Math.hypot(x, y);

				return distance
			},
			scanResult(result) {
				uni.showLoading({
					title: "开始识别"
				})
				this.$util.doGet(
					`/api/yun-bag/equipment/spread-qr-equipment/analysis/info?qrContent=${result}`, {}, {},
					true).then(res => {

					console.log("设备信息", res.data)
					this.equipment = res.data
					if (this.equipment) {
						uni.getLocation({
							type: 'gcj02',
							highAccuracyExpireTime: 12000,
							success: (res) => {
								this.latitude = res.latitude
								this.longitude = res.longitude
								this.equipLatitude = this.equipment.lat
								this.equipLongitude = this.equipment.lng
								let distance = this.distance()
								if (uni.getSystemInfoSync().platform ==
									'ios') {
									distance = this.iosDistance()
								}
								let equipmentDistance = uni.getStorageSync(
									"distance")
								if (distance <= equipmentDistance) {
									this.navTo(
										`/pages/index/equipment-info/equipment-info?equipment=${JSON.stringify(this.equipment)}`
									)
								} else {
									this.$util.showInfoToast("请在云袋机器旁扫码")
								}
								uni.hideLoading()
								console.log("设备距离", distance)
							},
							fail: (err) => {
								uni.hideLoading()
								this.$util.showInfoToast("获取位置失败")
							}
						});
					} else {
						uni.hideLoading()
						this.$util.showInfoToast("没有识别到设备信息")
					}

				}).catch(error => {
					console.log(error)
					this.$util.showInfoToast("获取设备信息失败")
					uni.hideLoading()
				})
			},
			async queryList() {
				//组件加载时会自动触发此方法，因此默认页面加载时会自动触发，无需手动调用
				//这里的pageNo和pageSize会自动计算好，直接传给服务器即可
				//模拟请求服务器获取分页数据，请替换成自己的网络请求
				const list = await this.getMicInforList(this.consultPage)
				this.articleList = this.articleList.concat(list);
				if (this.articleList.length > 0) {
					uni.setStorageSync("articleList", this.articleList)
				}
			},
			itemClick(index, info) {
				this.articleIndex = index
				this.$util.saveDynamicConsultation(info)
				this.navTo("/pages/index/article/article")
			},
			dialogConfirm() {
				permision.requestAndroidPermission('android.permission.CALL_PHONE').then(
					res => {
						console.log("权限状态", res)
						if (res === 1) {
							uni.makePhoneCall({
								phoneNumber: this.phoneNumber.replace(/\s+/g, "-")
							});
						} else if (res === -1) {
							uni.showModal({
								title: '提示',
								content: '您拒绝了拨打电话权限，当无法正常使用的时候，请去手动授权！',
								confirmText: "去授权",
								success: res => {
									if (res.confirm) {
										permision.gotoAppPermissionSetting();
									} else if (res.cancel) {
										console.log('用户点击取消');
									}
								}
							});
						}
					}).catch(error => {
					console.log(error)
				})

			},
			dialogClose() {
				// this.initial = "initial"
			},
			navTo(url) {
				if (this.labelCount === 0) {
					this.navTo("/pages/index/interest/interest")
					return;
				}
				if (!this.userInfo.phonenumber && this.isAndroid) {
					url = "/pages/user/my-setting/update-Phone/update-Phone"
				}
				if (!this.hasUserInfo) {
					if (url.indexOf("nearby-facility") != -1 || url.indexOf("article") != -1) {

					} else {
						url = "/pages/login/login"
					}
				}
				uni.navigateTo({
					url: url
				})
			},
			reLaunch(url, types) {
				getApp().globalData.types = types;
				uni.switchTab({
					url: url
				})
			},
			switchTabs(data) {
				if (data.index === 2 && !this.isAndroid && !this.iosStatus) {
					this.checkSystemLocationStatus();
					return
				}
				if (!this.hasUserInfo) {
					uni.navigateTo({
						url: "/pages/login/login"
					})
					return;
				}
				if (this.labelCount === 0) {
					uni.navigateTo({
						url: "/pages/index/interest/interest"
					})
					return;
				}
				uni.switchTab({
					url: data.url
				})
			},
			interval() {
				this.timerGif = setTimeout(() => {
					this.isGif = true
					this.gifUrl = "/static/index/money.gif"
				}, 1000)
				this.timerAnimation = setTimeout(() => {
					this.animation = ''
					this.isGif = false
					this.gifUrl = ""
				}, 3000)
			}
		},
		beforeDestroy() {
			clearInterval(this.timerShake);
			this.timerShake = null;
			clearInterval(this.timerAnimation);
			this.timerAnimation = null;
			clearInterval(this.timerGif);
			this.timerGif = null;
		}
	}
</script>

<style lang="scss">
	page {}

	.ad-content-page {
		flex: 1
	}

	.popup-content {
		width: 630rpx;
		height: 640rpx;
		border: solid 20rpx #E1443C;
		padding: 20rpx 0rpx;
		background-color: #FFFFFF;
		border-radius: 30rpx;
		border-image: linear-gradient(90deg, #E1463D, #D03653) 1;
		margin-bottom: 34rpx;
		clip-path: inset(0 0 round 15px);

		.popup-bottom {
			font-size: 26rpx;
			color: #CA9994;
			text-align: center;
			position: absolute;
			width: 630rpx;
			// height: 50rpx;
			// line-height: 50rpx;
			bottom: 80rpx;
		}

		.popup-button {
			width: 500rpx;
			height: 80rpx;
			line-height: 80rpx;
			color: #FFFFFF;
			background: linear-gradient(#EC6C52, #EA3833);
			text-align: center;
			border-radius: 50rpx;
			position: absolute;
			bottom: 150rpx;
			left: 50%;
			transform: translate(-50%, 0%);
		}

		.popup-content-item {
			width: 155rpx;
			height: 155rpx;
			border-radius: 15rpx;
			border: solid 5rpx #EC6338;
			margin-left: 41rpx;
			margin-top: 20rpx;

			view:nth-child(1) {
				height: 40rpx;
				background-color: #EB5936;
				font-size: 24rpx;
				color: #FFFFFF;
				text-align: center;
			}

			view:nth-child(2) {
				text-align: center;
				color: #EB5936;
				font-size: 40rpx;
				margin-top: 35rpx;
			}
		}
	}

	.popop-content {
		width: 630rpx;
		height: 800rpx;
		border: solid 20rpx #ff0000;
		border-radius: 15rpx;
		background-color: #FFFFFF;
	}

	.centre-top {
		position: fixed;
		z-index: 2;
		background-color: $index-bg-top;
		width: 100%;
		height: 110rpx;
		top: 0rpx;
		// padding-top: ;
		padding: 5rpx 0rpx;

		.search {
			width: 500rpx;
			padding: 20rpx 20rpx;
			background-color: #189FF9;
			border-radius: 50rpx;
			align-content: center;
		}
	}

	.centre-top1 {
		width: 100%;
		height: 320rpx;
		position: relative;
		z-index: -1;
		overflow: hidden;
	}

	.centre-top1:after {
		content: '';
		width: 120%;
		height: 320rpx;
		position: absolute;
		left: -10%;
		top: 0;
		z-index: -1;
		border-radius: 0 0 60% 60%;
		background: $index-bg-top;
	}


	.advertising {

		justify-content: space-around;
		align-items: center;
		padding: 15rpx 0rpx;

		image {
			width: 130rpx;
		}

		.button {
			padding: 15rpx 30rpx;
			background-color: $index-bg-top;
			border-radius: 35rpx;
			font-size: 24rpx;
			color: #FFFFFF;
		}

		.column {
			width: 298rpx;
			justify-content: flex-end;
			height: 100rpx;
		}
	}

	.advertising-img {
		width: 720rpx;
		background-color: #C0C0C0;
		text-align: center;
		border-radius: 35rpx;
		height: 300rpx;
		margin-top: 50rpx;
	}

	.centre-grid {
		padding: 0rpx 30rpx;
		position: relative;
		top: -20rpx;

		.row {
			position: relative;
			align-items: center;
			justify-content: space-around;
			bottom: 40rpx;
		}

		.animation-shake {
			animation: shake 1s !important;
		}

		@keyframes shake {

			0%,
			65% {
				-webkit-transform: rotate(0deg);
				transform: rotate(0deg);
			}

			70% {
				-webkit-transform: rotate(10deg);
				transform: rotate(10deg);
			}

			75% {
				-webkit-transform: rotate(-10deg);
				transform: rotate(-10deg);
			}

			80% {
				-webkit-transform: rotate(10deg);
				transform: rotate(10deg);
			}

			85% {
				-webkit-transform: rotate(-10deg);
				transform: rotate(-10deg);
			}

			90% {
				-webkit-transform: rotate(10deg);
				transform: rotate(10deg);
			}

			95% {
				-webkit-transform: rotate(-10deg);
				transform: rotate(-10deg);
			}

			100% {
				-webkit-transform: rotate(0deg);
				transform: rotate(0deg);
			}
		}

		.column {
			justify-content: flex-end;
			align-items: center;
			height: 220rpx;

			image {
				width: 120rpx;
				height: 120rpx;
			}

			.text-18 {
				font-size: 24rpx;
			}

		}
	}

	.text-sm {
		font-size: 26rpx;
		color: #D72816;
		margin-top: 15rpx;
	}

	.text-lg {
		font-size: 34rpx;
	}

	.article-list {
		image {
			width: 230rpx;
			height: 150rpx;
			border-radius: 20rpx;
		}

		.column-article {
			width: 450rpx;
			margin-left: 20rpx;
			height: 140rpx;
			justify-content: space-between;
		}

		.label {
			height: 90rpx;
			overflow: hidden;
			text-overflow: clip;
			display: -webkit-box;

			&:before {
				content: attr(contents);
				padding: 5rpx 10rpx;
				text-align: center;
				background-color: $index-bg-top;
				border-radius: 5rpx;
				font-size: 24rpx;
				color: #FFFFFF;
				margin-right: 10rpx;
			}
		}

		.label-text {
			text {
				font-size: 22rpx;
			}

			text:nth-child(-n+3) {
				color: #C0C0C0;
			}
		}
	}
</style>
